using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content.Pipeline;
using Microsoft.Xna.Framework.Content.Pipeline.Graphics;
using Microsoft.Xna.Framework.Content.Pipeline.Processors;

using NuclexVectorFontProcessor = Nuclex.Fonts.Content.NuclexVectorFontDescriptionProcessor;
using NuclexVectorFontContent = Nuclex.Fonts.Content.VectorFontContent;
using NuclexVectorFontCharacterContent = Nuclex.Fonts.Content.VectorFontCharacterContent;

namespace Qreed.Xna.Font.ContentPipeline
{
    /// <summary>
    /// This class will be instantiated by the XNA Framework Content Pipeline
    /// to apply custom processing to content data, converting an object of
    /// type TInput to TOutput. The input and output types may be the same if
    /// the processor wishes to alter data without changing its type.
    ///
    /// This should be part of a Content Pipeline Extension Library project.
    ///
    /// TODO: change the ContentProcessor attribute to specify the correct
    /// display name for this processor.
    /// </summary>
    [ContentProcessor(DisplayName = "VectorFont - Qreed Framework")]
    public class VectorFontProcessor : ContentProcessor<FontDescription, VectorFontContent>
    {
        public override VectorFontContent Process(FontDescription input, ContentProcessorContext context)
        {
            NuclexVectorFontProcessor nuclexProcessor = new NuclexVectorFontProcessor();
            NuclexVectorFontContent nuclexFontContent = nuclexProcessor.Process(input, context);

            VectorFontContent content = new VectorFontContent(nuclexFontContent);

            content.FontName = input.FontName;
            content.Process();

            if (input.Spacing > 0.0f)
            {
                foreach (char c in content.CharacterMap.Keys)
                {
                    VectorFontCharacterContent vc = content.CharacterMap[c];

                    vc.NuclexCharContent.Advancement += new Vector2(input.Spacing, 0.0f);
                }
            }

            return content;
        }
    }
}